package leetcode;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-5-30
 * Time: 下午7:22
 * To change this template use File | Settings | File Templates.
 */

import java.util.ArrayList;
import java.util.List;

/**
 * Definition for binary tree
 *
 */
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
public class Solution7 {

        public void inTree(ArrayList<Integer> list,TreeNode root){
            if(root.left!=null){
                inTree(list,root.left);
            }
            if(root.right!=null){
                inTree(list,root.right);
            }
            list.add(root.val);
        }
        public List<Integer> postorderTraversal(TreeNode root) {
            ArrayList<Integer> list = new ArrayList<Integer>();
            if(root.left!=null){
                inTree(list,root.left);
            }
            if(root.right!=null){
                inTree(list,root.right);
            }
            list.add(root.val);
            return list;
        }
    public static void main(String[] args){
        TreeNode node1 = new TreeNode(3);
        node1.right = new TreeNode(2);
        node1.left = new TreeNode(1);
        //node1.right.left = new TreeNode(3);
        Solution7 solution6 = new Solution7();

        ArrayList<Integer> list = (ArrayList<Integer>) solution6.postorderTraversal(node1);
        for(Integer integer:list){
            System.out.println(integer);
        }
    }
}
